const validateMixin = {
  data() {
    return {}
  },

  methods: {
    validateUserId: (userId, maxlength, minlength) => {
      let res = ''
      // 检查是否只包含英文字符或数字
      if (!/^[a-zA-Z0-9]+$/.test(userId)) {
        res = '账户名只能包含英文字符和数字'
      } else if (userId.length < minlength) {
        res = `账户名最短${minlength}位`
      } else if (userId.length == maxlength) {
        res = `账户名最长${maxlength}位`
      }
      return res
    },
    validatePassword(password, maxlength, minlength) {
      let res = ''
      // 检查是否只包含英文字符或数字
      if (!/^[a-zA-Z0-9]+$/.test(password)) {
        res = '密码只能包含英文字符和数字'
      } else if (password.length < minlength) {
        res = `密码最短${minlength}位`
      } else if (password.length == maxlength) {
        res = `密码最长${maxlength}位`
      }
      return res
    },
    validateConfirmPwd(password, repassword) {
      let res = ''
      if (repassword !== password) {
        res = '两次密码不一致'
      }

      return res
    }
  }
}

export default validateMixin
